import torch
from perceptron_model import Perceptron
from net_model import Net

# 创建模型列表
models = [Perceptron(), Net()]
for model in models:
    # 加载模型参数
    model.load_state_dict(torch.load(f'{model.__class__.__name__}_model.pth'))
    # 将模型设置为评估模式
    model.eval()
    # 打印模型结构
    print(f'{model.__class__.__name__} model structure:')
    print(model)
    with torch.no_grad():
        # 创建测试输入
        x_test = torch.tensor([10.0])
        # 使用模型进行预测
        y_test = model.to('cpu')(x_test.unsqueeze(0))
        # 打印输入和输出
        print(f'Text input: {x_test.item()}, Text output:{y_test.squeeze().item()}\n') 